package org.example.footshoppingmaster.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.footshoppingmaster.pojo.DO.Cart;
import org.example.footshoppingmaster.pojo.DTO.CartProduct;

import java.util.List;

@Mapper
public interface CartMapper {
    /*
     * 向购物车添加数据
     * */
    @Insert("INSERT INTO t_user_car (goodsId, goodsNum, userId, create_time, update_time) VALUES (#{goodsId}, #{goodsNum}, #{userId}, #{createTime}, #{updateTime});")
    int insertGoodsToCart(Cart cart);
    /*
     * 获取购物车商品列表
     * */
    @Select("SELECT t_shoes_all.id AS id,\n" +
            "       t_shoes_all.name AS name,\n" +
            "       t_shoes_all.price AS price,\n" +
            "       t_shoes_all.img AS img,\n" +
            "       t_shoes_all.info AS info,\n" +
            "       t_shoes_all.type AS type,\n" +
            "       t_shoes_all.brand AS brand,\n" +
            "       t_user_car.goodsNum AS goodsNum,t_user_car.id As cartId\n" +
            "FROM t_user_car\n" +
            "JOIN t_shoes_all ON t_user_car.goodsId = t_shoes_all.id\n" +
            "WHERE t_user_car.userId = #{id};")
    List<CartProduct> selectGoodsList(Integer id);
    /*
     * 删除购物车商品
     * */
    @Delete("delete from t_user_car where id=#{id}  ")
    boolean deleteGoods(Integer id);
}
